<template>
  <div>
    <el-dialog
      title="有蚁列表→有蚁处理"
      :visible.sync="show"
      :before-close="cancel"
      width="40%"
    >
      <div class="formBox">
        <div class="formHead">有蚁处理</div>
        <div class="formWhite">
          <div class="left">点位号</div>
          <div class="right">{{ itemForm.id }}</div>
        </div>

        <div class="formWhite area">
          <div class="left">所属项目</div>
          <div class="right">{{ itemForm.projectName }}</div>
        </div>
        <div class="formWhite">
          <div class="left">监测公司</div>
          <div class="right">{{ itemForm.monitorName }}</div>
        </div>
        <div class="formWhite">
          <div class="left">经纬度</div>
          <div class="right">{{ itemForm.location }}</div>
        </div>
        <div class="formWhite">
          <div class="left">所属白蚁防治公司</div>
          <div class="right">{{ itemForm.controlName }}</div>
        </div>
        <div class="formWhite">
          <div class="left">中继/IP</div>
          <div class="right">{{ itemForm.relay }}</div>
        </div>
        <div class="formWhite">
          <div class="left">RSSI</div>
          <div class="right">{{ itemForm.rssi }}</div>
        </div>
        <div class="formWhite">
          <div class="left">SNR</div>
          <div class="right">{{ itemForm.snr }}</div>
        </div>
        <div class="formWhite">
          <div class="left">电压</div>
          <div class="right">{{ itemForm.voltage }}</div>
        </div>
        <div class="formWhite">
          <div class="left"><span class="red">*</span>是否是白蚁</div>
          <div class="right">
            <!-- 改 -->
            <el-select
              v-model="itemForm.termiteIs"
              placeholder="请选择"
              filterable
              clearable
              size="small"
            >
              <el-option
                v-for="users in specificList"
                :key="users.value"
                :label="users.label"
                :value="users.value"
              />
            </el-select>
          </div>
        </div>
        <div class="formWhite" style="height: 220px">
          <div class="left" style="height: 220px; line-height: 220px">
            <span class="red">*</span>上传现场照片
          </div>
          <div class="right" style="height: 100%">
            <imageUpload :limit="1" v-model="itemForm.photoTermite" />
          </div>
        </div>
        <div
          class="formWhite"
          style="height: 220px"
          v-if="itemForm.termiteIs == '是'"
        >
          <div class="left" style="height: 220px; line-height: 220px">
            <span class="red">*</span>上传处理照片
          </div>
          <div class="right" style="height: 220px">
            <imageUpload :limit="1" v-model="itemForm.photoControl" />
          </div>
        </div>
        <!-- <div
          class="formWhite"
          style="height: 220px"
          v-if="itemForm.termiteIs == '否'"
        >
          <div class="left" style="height: 220px; line-height: 220px">
            上传现场照片
          </div>
          <div class="right" style="height: 220px">
            <imageUpload :limit="1" v-model="itemForm.photoControl" />
          </div>
        </div> -->

        <div class="formWhite" v-if="itemForm.termiteIs == '否'">
          <div class="left"><span class="red">*</span>误报原因</div>
          <div class="right">
            <el-select
              v-model="itemForm.reasonAlarm"
              placeholder="请选择"
              filterable
              clearable
              size="small"
            >
              <el-option
                v-for="users in reasonList"
                :key="users.value"
                :label="users.label"
                :value="users.value"
              />
            </el-select>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="enSure" size="small">确定</el-button>
        <el-button type="primary" plain @click="cancel" size="small"
          >取消</el-button
        >
      </span>
    </el-dialog>
    <!-- <div class="mainName">监测点管理→监测点{{ myTitle }}</div> -->
    <!-- <div class="btnGroupLeft">
      <div class="left">
        
      </div>
    </div>-->
  </div>
</template>

<script>
import {
  addProjectData, // 新增项目
  updateProjectData, // 项目编辑
  termiteHandle, // 有蚁列表->有蚁处理
} from "@/api/manage/asset";
export default {
  props: ["submitForm", "detailDis", "id", "detailRow", "show"],
  data() {
    return {
      reasonList: [
        {
          value: "木材腐烂",
          label: "木材腐烂",
        },
        {
          value: "人为破坏",
          label: "人为破坏",
        },
        {
          value: "设备调试",
          label: "设备调试",
        },
        {
          value: "模块更换",
          label: "模块更换",
        },
        {
          value: "其他昆虫",
          label: "其他昆虫",
        },
      ],
      specificList: [
        {
          value: "是",
          label: "是",
        },
        {
          value: "否",
          label: "否（误报）",
        },
      ],
      itemForm: {},
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      console.log(this.id, "00000000");
      this.itemForm = { ...this.submitForm };
    },
    enSure() {
      console.log(this.itemForm, "this.itemForm");
      if (!this.itemForm.termiteIs) {
        this.$modal.msgWarning("请选择是否是白蚁");
      } else if (
        this.itemForm.termiteIs == "否" &&
        (!this.itemForm.photoTermite || !this.itemForm.reasonAlarm)
      ) {
        this.$modal.msgWarning("请上传现场照片以及误报原因");
      } else if (
        this.itemForm.termiteIs == "是" &&
        (!this.itemForm.photoTermite || !this.itemForm.photoControl)
      ) {
        this.$modal.msgWarning("请上传现场照片以及处理照片");
      } else {
        const data = {
          id: this.itemForm.id,
          projectName: this.itemForm.projectName,
          projectId: this.itemForm.projectId,
          monitorName: this.itemForm.monitorName,
          location: this.itemForm.location,
          controlName: this.itemForm.controlName,
          controlId: this.itemForm.controlId,
          relay: this.itemForm.relay,
          rssi: this.itemForm.rssi,
          snr: this.itemForm.snr,
          voltage: this.itemForm.voltage,
          termiteIs: this.itemForm.termiteIs,
          photoTermite: this.itemForm.photoTermite,
          // photoControl: this.itemForm.photoControl, // 否的时候不传
          // reasonAlarm: this.itemForm.reasonAlarm, // 是的时候不传
        };
        if (this.itemForm.termiteIs == "是") {
          data.photoControl = this.itemForm.photoControl;
        }
        if (this.itemForm.termiteIs == "否") {
          data.reasonAlarm = this.itemForm.reasonAlarm;
        }
        termiteHandle(data)
          .then((res) => {
            if (res.errorCode == "000000") {
              this.$modal.msgSuccess("处理成功！");
            }
          })
          .finally(() => {
            this.$emit("closeMsg", true);
          });
      }
    },
    cancel() {
      this.$emit("closeMsg");
    },
  },
};
</script>

<style lang="scss" scoped>
// .app-main {
.formBox {
  .left {
    display: inline-block;
    height: 44px;
    line-height: 44px;
    width: 120px;
    padding-right: 15px;
    border-left: 1px solid #e4e4dc;
    border-right: 1px solid #e4e4dc;
    font-family: MicrosoftYaHei;
    font-size: 12px;
    color: #303133;
    text-align: right;
    vertical-align: top;
  }
  .right {
    display: inline-block;
    width: calc(100% - 120px);
    height: 44px;
    line-height: 32px;
    border-right: 1px solid #e4e4dc;
    padding: 6px 15px;
    .el-select {
      width: 100% !important;
    }
    .el-input {
      width: 100% !important;
    }
  }
  .formHead {
    width: 100%;
    height: 44px;
    background-color: #5d6d7f;
    height: 44px;
    line-height: 44px;
    text-align: center;
    font-family: MicrosoftYaHei, MicrosoftYaHei;
    font-weight: bold;
    font-size: 12px;
    color: #ffffff;
  }
  .formWhite {
    width: 100%;
    height: 44px;
    background-color: #fff;
    border-bottom: 1px solid #e4e4dc;
  }
  .formGray {
    width: 100%;
    height: 44px;
    background-color: #dbe2e6;
    border-bottom: 1px solid #e4e4dc;
  }
}
.mainName {
  font-family:
    PingFangSC,
    PingFang SC;
  font-weight: 500;
  font-size: 16px;
  height: 30px;
  line-height: 30px;
  color: #000000;
  border-bottom: 1px solid #dcdfe6;
  margin-bottom: 10px;
}
::v-deep .el-dialog__header {
  border-bottom: 1px solid #e9e9ec;
}
::v-deep .el-dialog__footer {
  border-top: 1px solid #e9e9ec;
}
// }
.el-collapse .el-collapse-item__header {
  font-size: 16px;
  font-weight: bold;
}

.pagination-container {
  margin-top: 20px;
  width: 100%;
}

.pagination-container .el-pagination {
  display: flex;
  justify-content: center;
  width: 100%;
}
.red {
  color: red;
  margin-right: 2px;
  vertical-align: top;
}
</style>
